public class Vt {
    static public final char UP = 'A';
    static public final char DOWN = 'B';
    static public final char LEFT = 'D';
    static public final char RIGHT = 'C';

    static public final String SAVE = "s";
    static public final String LOAD = "u";
    static public final String HIDE = "?25l";
    static public final String SHOW = "?25h";

    static public final String SCREEN = "2J";
    static public final String ALLLINE = "2K";
    static public final String LINE = "K";

    static private Vt vt = null;

    private Vt() {}

    static public Vt getVt() {
        if (vt == null)
            vt = new Vt();
        return vt;
    }

    static public void p(String format, Object ... obj) {
        System.out.printf(format, obj);
    }

    // 绝对定位
    static public Vt gotoxy(int r, int c) {
        p("\033[%d;%dH", r, c);
        return getVt();
    }
    // 相对定位
    static public Vt move(char dir, int step) {
        p("\033[%d%s", step, dir);
        return getVt();
    }
    // 隐藏光标
    // 显示光标
    // 保存光标
    // 还原光标
    // 清屏
    // 清整行
    // 清除光标后面内容
    static public Vt cmd(String op) {
        p("\033[%s", op);
        return getVt();
    }

    // 颜色输出
    static public Vt out(String s, int ... color) {
        String cmd = "";

        /*
         * 30 40 1
         * 30 40
         * 30
         * 40
         * 1
         */

        if (color.length >= 1) {
            cmd += color[0];
            if (color.length > 1) {
                cmd += ";" + color[1];
            }
            if (color.length > 2 && color[2] == 1) {
                cmd += ";1";
            }
        }
        p("\033[%sm%s\033[0m", cmd, s);

        return getVt();
    }

    // static public void main(String [] args) {
        /*
         * for (int i = 0; i < 8; ++i) {
         *     out("hello ", 30 + i, 1);
         *     out("hello ", 30 + i);
         *     out("hello ", 40 + i, 1);
         *     out("hello ", 40 + i);
         *     out("world ", 1);
         *     p("\n");
         * }
         */
    // }
}
